package ch.bfh.fbi.mobicomp.zap02;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import ch.simplix.android.speech.string.UKString;

/**
 * We can even use some other services (Libraries) in order to enrich our application.
 * @author SimpliX
 *
 */
public class Zap02MessageBroadcastReceiver extends BroadcastReceiver {
	private static final String TAG = "Zap02MessageBroadcastReceiver";
	private static final String destructionKey = "destroyMe";
	private static final String haltKey = "stopDestroyMe";

	@Override
	public void onReceive(Context context, Intent intent) {
		Intent speechIntent = new Intent("ch.simplix.android.speech.SPEECH_SERVICE");
		
		if (intent.getExtras().getBoolean(destructionKey)) {
			Log.d(TAG, "destruction initiated...");	
			speechIntent.putExtra("Phrase", new UKString(
					"Self destruction sequence initiated."));
			context.startService(speechIntent);
		} else if (intent.getExtras().getBoolean(haltKey)) {
			Log.d(TAG, "destruction aborted...");
			speechIntent.putExtra("Phrase", new UKString(
					"Self destruction sequence aborted."));
			context.startService(speechIntent);
		}else{
			Log.d(TAG, "unknown command.");
		}
		
	}
}
